// Using the closure to map jQuery to $. 
(function ($) {

// Store our function as a property of Drupal.behaviors.
Drupal.behaviors.deployment = {
	attach: function(context, settings) {
		$(".pkg-validating").each(function(){
			id = $(this).attr("id");
			ticket_id = id.replace("status-", "");
			pull_status(ticket_id);
		});
		
		
		
		function pull_status(ticket_id) {
			$.ajax({
				url: 'deployment/get_package_status/'+ticket_id, 
				success: function(data) {
					switch (data) {
					case "3":
//						$("#status-"+ticket_id).html("Pending");
//						$("#action-"+ticket_id).html("");
						window.location.replace('deployment');
						break;
					}
//					$("#action-"+ticket_id).append(data);
				},
				complete: function() {
					// Schedule the next request when the current one's complete
					setTimeout(function() {pull_status(ticket_id);}, 5000);
				},
			});
		}
		
	}
};
}(jQuery));